const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       this.setData({
            orderIds: options.orderIds,
            payAmount: options.payAmount,
            cartType:options.cartType
       }); 
       let that = this
       var data = { 'orderIds': that.data.orderIds}
       var promise = app.synPostData('pay/prepay', data)
       promise.then(function (res) {
            console.log("返回的" + res.data.result.orderNo)
            that.setData({
                 orderNo: res.data.result.orderNo,
                 payAmount: res.data.result.payAmount
            })
       }); 
       
    
  },


     // 跳转到支付成功
     toPaymentSu: function () {
          let orderNo = this.data.orderNo
          let that = this
          var data = { 'memberId': app.globalData.userInfo.id, 'outTradeNo': orderNo }
          
          var promise = app.synPostData('pay/wechat/paySign', data)
          promise.then(function (res) {
               let timeStamp = res.data.result.timeStamp
               let nonceStr = res.data.result.nonceStr
               let package1 = res.data.result.package_
               let signType = res.data.result.signType
               let paySign = res.data.result.paySign

               if (res.data.code != 0) {
                    wx.showToast({
                         title: "支付异常",
                         icon: 'none',
                         duration: 1500
                    })
               } else {
                    console.log("微信签名" + paySign)
                    wx.requestPayment({
                         timeStamp: timeStamp,
                         nonceStr: nonceStr,
                         package: package1,
                         signType: signType,
                         paySign: paySign,
                         'success': function (res) {
                              wx.navigateTo({
                                   url: '../payment-success/payment-success?cartType=' + that.data.cartType + '&orderIds=' + that.data.orderIds+'&payAmount='+that.data.payAmount  
                              })
                         },
                         'fail': function (res) {

                         }
                    })
                    console.log("返回的结果" + res.data.result.timeStamp)
               }
          }); 
     }
  

 

})